package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.priceconfig.LindiPriceConfigQueryVO;
import com.minimalist.common.entity.lindi.vo.priceconfig.LindiPriceConfigVO;
import com.minimalist.common.feign.client.lindi.LindiPriceConfigFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地价格配置 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiPriceConfigFeignClientFallbackFactory extends BaseFallbackFactory<LindiPriceConfigFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(LindiPriceConfigFeignClientFallbackFactory.class);

    @Override
    public LindiPriceConfigFeignClient create(Throwable cause) {
        return new LindiPriceConfigFeignClient() {
            @Override
            public R<?> addPriceConfig(LindiPriceConfigVO priceConfigVO) {
                logServiceUnavailable("添加价格配置", priceConfigVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "添加价格配置失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updatePriceConfigByPriceConfigId(LindiPriceConfigVO priceConfigVO) {
                logServiceUnavailable("修改价格配置", priceConfigVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "修改价格配置失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deletePriceConfigByPriceConfigId(Long priceConfigId) {
                logServiceUnavailable("删除价格配置", priceConfigId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "删除价格配置失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiPriceConfigVO> getPriceConfigByPriceConfigId(Long priceConfigId) {
                logServiceUnavailable("获取价格配置详情", priceConfigId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "获取价格配置详情失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiPriceConfigVO>> getPagePriceConfigList(LindiPriceConfigQueryVO queryVO) {
                logServiceUnavailable("分页查询价格配置列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "分页查询价格配置列表失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}